package com.mall.server.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.commons.R;
import com.mall.server.service.SubjectService;
import com.tanhua.model.domain.CmsSubject;
import com.tanhua.model.domain.SmsHomeNewProduct;
import com.tanhua.model.vo.PageVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/subject")
public class SubjectController {
    @Autowired
    private SubjectService subjectService;


    /**
     * 获取全部商品专题
     * @return
     */
    @GetMapping("/listAll")
    public R listAll(){
        List<CmsSubject> cmsSubjectList=subjectService.listAll();
        return R.success(cmsSubjectList);
    }

    /**
     * 根据专题名称分页获取商品专题
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public R subjectList(String keyword,
                            @RequestParam(defaultValue = "1")Integer pageNum,
                            @RequestParam(defaultValue = "5")Integer pageSize){
        Page<CmsSubject> page = new Page<>(pageNum,pageSize);
        PageVo pageVo =subjectService.subjectList(keyword,page);
        return R.success(pageVo);
    }


}
